package com.ruoyi.student.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;

import java.util.List;
import java.util.Map;

import com.ruoyi.student.mapper.StudentCourseMapper;
import com.ruoyi.student.domain.StudentCourse;
import com.ruoyi.student.service.IStudentCourseService;

/**
 * 学生课Service业务层处理
 *
 * @author 刘红
 * @date 2023-11-29
 */
@Service
public class StudentCourseServiceImpl extends ServiceImpl<StudentCourseMapper, StudentCourse> implements IStudentCourseService {

    @Autowired
    private StudentCourseMapper studentCourseMapper;

    /**
     * 查询学生课列表
     *
     * @param studentCourse 学生课
     * @return 学生课
     */
    @Override
    public List<StudentCourse> selectStudentCourseList(StudentCourse studentCourse) {
        studentCourse.setUserId(SecurityUtils.getLoginUser().getUserId());
        List<StudentCourse> studentCourseList = studentCourseMapper.selectList(buildQueryWrapper(studentCourse));
        return studentCourseList;
    }


    private LambdaQueryWrapper<StudentCourse> buildQueryWrapper(StudentCourse query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<StudentCourse> lqw = Wrappers.lambdaQuery();
        lqw.eq(query.getUserId() != null, StudentCourse::getUserId, query.getUserId());
        lqw.eq(query.getCourseId() != null, StudentCourse::getCourseId, query.getCourseId());
        lqw.like(StringUtils.isNotBlank(query.getCourseName()), StudentCourse::getCourseName, query.getCourseName());
        lqw.eq(query.getScore() != null, StudentCourse::getScore, query.getScore());
        lqw.eq(query.getMonday() != null, StudentCourse::getMonday, query.getMonday());
        lqw.eq(query.getTuesday() != null, StudentCourse::getTuesday, query.getTuesday());
        lqw.eq(query.getWednesday() != null, StudentCourse::getWednesday, query.getWednesday());
        lqw.eq(query.getThursday() != null, StudentCourse::getThursday, query.getThursday());
        lqw.eq(query.getFriday() != null, StudentCourse::getFriday, query.getFriday());
        lqw.orderByDesc(StudentCourse::getCreateTime);
        return lqw;
    }

}
